pp108 : Mapping Object

Mapping Object


A Mapping Object represents the XML that contains information about mapping of data between a source and a target. It is possible to map data from a model to any control in an XForm, using a Message Map.

At run time, a mapping assignment is handled by a (run-time) method calledmakeAssignments(). So, for data to be mapped correctly, themakeAssignments()method must be implemented for the control to be mapped.

ThemakeAssignments()method is associated with theassignmentObjectparameter. This parameter comprises information about the mapping and can be used with a set of methods to iterate through mapped data.

Properties and Methods


The properties and methods available for use with theassignmentObjectparameter are as follows.

Table 1. List of properties available for assignmentObject

Property

Description

srcElement

Refers to the control on which the event that triggered the mapping is fired.

targetElement

Refers to the target element of the mapping.

eventName

Refers to the name of the event that triggers the mapping.


Table 2. List of Methods available for assignmentObject

Method

Description

getSourceValues()

Returns data available for mapping; can be a one- or two-dimensional array of data values from the source.

getNextMappedObject()

Returns an object that contains the sourceBusinessObject of the composite control as well as the businessObject of the model. The returned object is mapped to the schema format of the composite control.It works as an iterator. For example, if n objects are available, it will return the value n times and return null when called n+1 time.

getMappedObject(index)

Returns an object that contains the sourceBusinessObject of the composite control as well as the businessObject of the model. The returned object is mapped to the schema format of the composite control.Index specifies the index of the data object that is to be mapped.


Example


Consider associating theCityfield from theEmployeesmodel to a Google Map control so that the city can be located and shown on the map. To accomplish this, the following code would be required to be written for the On Row Select event of the control.

var activeBO = <model1>.getActiveBusinessObject().getCurrent();
var value = <model2>. getActiveBusinessObject().getCurrent();
cordys.selectXMLNode(activeBO,".//*[local-name()='City']") = value;


The Message Map enables you to map theCityfield from theEmployeesmodel with thecityfield from the Google Map control without using script. Such mapping is possible only if both the data sources have a schema representation of their data.

In the above case, theEmployeesmodel may use a WSDL definition while the Google Map control uses the Google schema.

The implementation of the example is as follows.

GoogleMap.prototype.makeAssignments = function(assignmentObject)
{
     var dataObject;
     while (dataObject = assignmentObject.getNextDataObject())
     {
          for (var i=0; i<assignmentObject.numberOfTargets; i++)
          {
              var city = "";
              var country = "";
              if (dataObject.targetPath[i].indexOf("City") > 0)
              {
                   city = dataObject.data[i];
              }
              else if (dataObject.targetPath[i].indexOf("Country") > 0)
              {
                   country = dataObject.data[i];
              }
          }
          this.createMarker(city, country);
     }
}